package com.gxa.insurance.controller;

import com.gxa.insurance.exception.BusinessException;
import com.gxa.insurance.exception.ExceptionCode;
import com.gxa.insurance.service.SalaryService;
import com.gxa.insurance.util.JsonResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author Min
 */
@RestController
@RequestMapping("/salary")
@CrossOrigin
public class SalaryController {
    @Autowired
    private SalaryService service;

    @ApiOperation("分页查询所有工资条目信息,如果传入页面数据小于0则自动设置为1,10")
    @PostMapping("/selectAll")
    public Map selectAll(@RequestParam("page")Integer page,@RequestParam("pageSize")Integer pageSize) throws BusinessException {
        if(page==null ||  pageSize==null){
            throw new BusinessException(ExceptionCode.WRONG_VALUE);
        }
        Map<String,Object> datas=service.selectAllSalary(page,pageSize);
        JsonResult jsonResult = new JsonResult();
        if(datas==null || datas.size()<=0){
            jsonResult.setCode("0");
            jsonResult.setMsg("查询失败");
        }else {
            jsonResult.setCode("1");
            jsonResult.setMsg("查询成功");
            jsonResult.setData(datas.get("list"));
            jsonResult.put("count",datas.get("count"));
        }
        return jsonResult.getMap();
    }
}
